package com.aaa.controller;


import com.aaa.Tool.TXT_file_tools;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.File;
import java.util.HashSet;

@Controller
@RequestMapping(value = "")
public class index {

    @GetMapping(value = "")
    public String index(Model model) {

//        Automatic_completion  自动补全

        TXT_file_tools txt_file_tools = new TXT_file_tools();

        String txt_folder_path = txt_file_tools.get_txt_folder_path();
        File folder = new File(txt_folder_path);  //  folder_path string 类型

        HashSet<String> all_file_path = txt_file_tools.get_all_file_path(folder);
        StringBuilder str = new StringBuilder();
        for (String path : all_file_path) {
            str.append("  ");
            String txt_file_title = txt_file_tools.get_txt_file_title(path);
//            System.out.println(txt_file_title);
            String english_words = txt_file_tools.get_english_words(txt_file_title);
            str.append(english_words);
        }
        String[] str_list = str.toString().split(" ");

        HashSet<String> stringHashSet = new HashSet<>();
        for (String s : str_list) {
            s = s.toLowerCase();
//            System.out.println(s);
            if (s.length() > 2){
                stringHashSet.add(s);
            }
        }

        System.out.println(stringHashSet);

        model.addAttribute("completion_words", stringHashSet);
        model.addAttribute("aaa", "aaa");

        return "index/index.html";
    }


}








